package com.yycx.module.bus.provider.controller.hy;

import cn.hutool.core.map.MapUtil;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.springmvc.base.BaseController;
import com.yycx.common.utils.DateUtils;
import com.yycx.module.bus.client.entity.hy.BusErpOrder;
import com.yycx.module.bus.provider.service.hy.BusErpOrderService;
import com.yycx.module.system.client.entity.SysCompany;
import com.yycx.module.system.provider.service.SysCompanyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


/**
 * 海鹰erp订单控制器
 *
 * @author flyme
 * @date 2023-02-07
 */
@RestController
@RequestMapping("/bus/beo/")
public class BusErpOrderController extends BaseController<BusErpOrderService, BusErpOrder> {
    @Autowired
    private SysCompanyService companyService;

    @ApiOperation(value = "海鹰erp订单-分页列表", notes = "海鹰erp订单分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        String beginDate= MapUtil.getStr(params,"beginDate", DateUtils.format(DateUtils.getFirstDayOfMonth()));
        String endDate= MapUtil.getStr(params,"endDate", DateUtils.format(DateUtils.getLastDayOfMonth()));
        params.put("beginDate", beginDate);
        params.put("endDate", endDate);
        return bizService.pageList(params);
    }

    @ApiOperation(value = "海鹰erp订单-列表", notes = "海鹰erp订单列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "海鹰erp订单-添加", notes = "添加海鹰erp订单")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "海鹰erp订单-更新", notes = "更新海鹰erp订单")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "海鹰erp订单-删除", notes = "删除海鹰erp订单")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "海鹰erp订单-详情", notes = "海鹰erp订单详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }


    @ApiOperation(value = "海鹰erp订单-生成单据凭证", notes = "海鹰erp订单-生成单据凭证")
    @PostMapping(value = "createVoucher")
    public ResultBody createVoucher(@RequestParam(required = false) Map params) {
        return bizService.createVoucher(params);
    }

    @ApiOperation(value = "海鹰erp订单-合并单据生成凭证", notes = "海鹰erp订单-合并单据生成凭证")
    @PostMapping(value = "mergeVoucher")
    public ResultBody mergeVoucher(@RequestParam(required = false) Map params) {
        return bizService.mergeVoucher(params);
    }

    @ApiOperation(value = "海鹰erp订单-合并生成当月单据凭证", notes = "海鹰erp订单-合并生成当月单据凭证")
    @PostMapping(value = "monthVoucher")
    public ResultBody monthVoucher(@RequestParam(required = false) Map params) {
        Long companyId = OpenHelper.getCompanyId();
        SysCompany company = companyService.getById(companyId);
        String dbName = company.getCompanyErpInstance();
        params.put("dbName", dbName);
        params.put("companyCode", company.getCompanyCode());
        params.put("companyId", company.getCompanyId());
        return bizService.monthVoucher(params);
    }

    @ApiOperation(value = "样品凭证", notes = "样品凭证")
    @PostMapping(value = "sampleVoucher")
    public ResultBody sampleVoucher(@RequestParam(value = "file") MultipartFile file) {
        return bizService.sampleVoucher(file);
    }

    @ApiOperation(value = "成本凭证", notes = "成本凭证")
    @PostMapping(value = "createCost")
    public ResultBody createCost(@RequestParam(required = false) Map params) {
        return bizService.createCost(params);
    }

    @ApiOperation(value = "付款凭证", notes = "付款凭证")
    @PostMapping(value = "createPayment")
    public ResultBody createPayment(@RequestParam(required = false) Map params) {
        return bizService.createPayment(params);
    }


    @ApiOperation(value = "套账下拉", notes = "套账下拉")
    @GetMapping(value = "getCompany")
    public ResultBody getCompany(@RequestParam(required = false) Map params) {
        return bizService.getCompany(params);
    }


    @ApiOperation(value = "更新凭证", notes = "更新凭证")
    @PostMapping(value = "updateOrder")
    public ResultBody updateOrder(@RequestParam(required = false) Map params) {
        return bizService.updateOrder(params);
    }

}
